package cn.school.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author oldliu
 * @since 1.0
 */
@WebFilter(filterName = "TimeFilter",value = "/*")
public class BTimeFiler implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //filterConfig.getInitParameter("xxx");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("进入了：TimeFilter");
        long start=System.nanoTime();
        filterChain.doFilter(servletRequest,servletResponse);
        long end=System.nanoTime();
        HttpServletRequest req= (HttpServletRequest) servletRequest;
        System.out.println(req.getServletPath()+"执行耗时"+(end-start)+"纳秒");
        System.out.println("离开了：TimeFilter");
    }

    @Override
    public void destroy() {

    }
}
